<?php
/**
 * AjaxController
 *
 * @author
 * @version
 */
require_once 'BaseAjaxController.php';
require_once 'configs/Config.php';

class AdminController extends BaseAjaxController {

	public function listUserAction()	{
		require_once('models/User.php');
		$user = new User(null);
		$this->view->response = array('result'=>$user->listUser());
	}
	
	public function editUserAction()	{
		require_once('models/User.php');
		$user = new User(null);
		$userId = $this->_getParam('id');
		$role = $this->_getParam('role');
		$this->view->response = array('result'=>$user->update(array('role'=>$role), 'id = '.$userId));
	}

	public function deletePermissionAction()	{
		require_once('models/Permission.php');
		$permission = new Permission(null);
		$id = $this->_getParam('id');
		$this->view->response = array('result'=>$permission->delete('id = '.$id));
	}

	public function addPermissionAction()	{
		require_once('models/Permission.php');
		$permission = new Permission(null);
		$role = $this->_getParam('role');
		$controller = $this->_getParam('controller');
		$action = $this->_getParam('action');
		$this->view->response = array('result'=>$permission->insertRowWithData(array('role_id'=>$role, 'controller'=>$controller, 'action'=>$action)));
	}
	
	public function addKeywordAction()	{
		require_once('models/Keywords.php');
		$kw = new Keywords(null);
		$content = $this->_getParam('content');
		$validator = $this->_getParam('validator');
		$this->view->response = array('result'=>$kw->insertRowWithData(array('content'=>$content, 'validator'=>$validator)));
	}
	
	public function editKeywordAction()	{
		require_once('models/Keywords.php');
		$kw = new Keywords(null);
		$id = $this->_getParam('id');
		$content = $this->_getParam('content');
		$validator = $this->_getParam('validator');
		$this->view->response = array('result'=>$kw->update(array('content'=>$content, 'validator'=>$validator), 'id='.$id));
	}
}